export const state = () => ({
  locales: ['zh', 'km'],
  locale: 'km',
  channel: null, //当前频道
  channels: [], //已点击过的频道
  newsList: []
});

export const mutations = {
  SET_LANG(state, locale) {
    if (state.locales.indexOf(locale) !== -1) {
      state.locale = locale;
    }
  },
  SET_CHANNEL(state, channel) {
    state.channel = channel;
  },
  SET_NEWS_LIST(state, news) {
    state.newsList.push({
      channelId: state.channel,
      news: news
    });
  }
};

export const getters = {
  localeFull: state => {
    const localeMap = {
      zh: 'zh-Hans',
      km: 'km-KH',
      en: 'km-KH'
    };
    return localeMap[state.locale];
  }
};
